package com.kaede.hayate.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Arrays;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Autowired
	private ApplicationProperties applicationProperties;

    @Bean
    public Docket api() {    	   	  	
        return new Docket(DocumentationType.SWAGGER_2)
        		.apiInfo(new ApiInfo("接口文档", "token前缀"+applicationProperties.getTokenPrefix(), "0.0.1", "", new Contact("Kaede", "", "hayatenokiseki@gmail.com"), "打开百度搜索", "https://www.baidu.com",new ArrayList<VendorExtension>()))
                .select()  // 选择那些路径和api会生成document
                	.apis(RequestHandlerSelectors.basePackage("com.kaede.hayate"))
                	.paths(PathSelectors.any()) 
                	.build()
                .securitySchemes(Arrays.asList(apiKey()))
                ;
    }
    
    private ApiKey apiKey() {
  	  return new ApiKey("Jwt", applicationProperties.getAuthorizationHeader(), "header");	//16	Here we use ApiKey as the security schema that is identified by the name mykey
  	}
}
